package com.ztools.mvp;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.ztools.base.BaseActivity;
import com.ztools.mvp.proxy.MvpBindCallback;
import com.ztools.mvp.proxy.impl.ActivityLifecycleCallbackProxy;


/**
 * <pre>
 *    author: summer
 *    time  : 2018/03/06
 * </pre>
 */

public abstract class BaseMvpActivity<V extends IView, P extends IPresenter<V>> extends BaseActivity implements MvpBindCallback<V, P> {

    private ActivityLifecycleCallbackProxy<V, P> mLifeCallback;

    private ActivityLifecycleCallbackProxy<V, P> getLifeCallbackProxy() {
        if (this.mLifeCallback == null) {
            this.mLifeCallback = new ActivityLifecycleCallbackProxy<>(this);
        }
        return this.mLifeCallback;
    }

    private P p;

    private V v;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        getLifeCallbackProxy().onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();
        getLifeCallbackProxy().onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        getLifeCallbackProxy().onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getLifeCallbackProxy().onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        getLifeCallbackProxy().onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
        getLifeCallbackProxy().onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getLifeCallbackProxy().onDestroy();
    }

    @Override
    public P newPresenter() {
        return this.p;
    }

    @Override
    public V newMvpView() {
        return this.v;
    }

    @Override
    public P getPresenter() {
        return this.p;
    }

    @Override
    public void setPresenter(P p) {
        this.p = p;
    }


    @Override
    public V getMvpView() {
        return this.v;
    }

    @Override
    public void setMvpView(V v) {
        this.v = v;
    }

    public Context getContext() {
        return this;
    }

    @Override
    public void bindUI() {

    }


}
